'use strict';

/* Controllers */
// signin controller
app.controller('SigninFormController', ['$scope', '$http', '$state', function ($scope, $http, $state) {
    $scope.user = {};
    $scope.authError = getAndRemoveStorage('go_to_login_msg');
    $scope.login = function () {
        $scope.authError = '';
        // Try to login
        $http.get(beetle_auth_url + '/login/?user_name=' + $scope.user.account + "&user_pass=" + $scope.user.password)
            .then(function (response) {
                var data = response.data;
                if (data.success == false) {
                    $scope.authError = data.msg;
                } else {
                    setTokenId(data.data.token_id);
                    $state.go('app.dashboard-v1');
                }
            }, function (x) {
                $scope.authError = 'Server Error';
            });
    };
}])
;